public class t14 {
    public static void main(String[] args){
        //定义字符串数组 寻找最长的公共前缀
        //例如：["flower","flow","flight"] 返回"fl"
        //["dog","racecar","car"] 返回 "" 不存在公共前缀
        String [] strs = new String[]{"cir","car"};
        int len = strs[0].length();
        for(int i =1;i<=strs.length-1;i++){
            if( len>strs[i].length() ){
                len = strs[i].length();
            }else{
                len = len;
            }
        }
        //System.out.println(len); 字符串数组中最小字符长度为len
        String a = "";
        int k = 1;
        for(int i =0 ; i<=len-1 ;i++){
            k=1;
            for(int j =0 ; j<=strs.length-2;j++){
                if( strs[j].substring(0,i+1).equals( strs[j+1].substring(0,i+1) ) ){
                                           k++;
                }
                if (k == strs.length) {
                        a += strs[j].substring(i, i + 1);
                }
            }
        }
        System.out.println(a);
    }
}


